//
//  UIBarButtonItem+YXExtence.m
//  彩票
//
//  Created by mac on 15-3-27.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "UIBarButtonItem+YXExtence.h"

@implementation UIBarButtonItem (YXExtence)

- (UIBarButtonItem *)initWith:(NSString *)norImage andSelecte:(NSString *)seletedImage andTitle:(NSString *)title andTarget:(id)target andActivity:(SEL)activity
{
    // 创建按钮
    UIButton *btn = [[UIButton alloc] init];
    // 设置高亮和默认时的图片
    if (norImage !=nil && ![norImage isEqualToString:@""]) {
        [btn setImage:[UIImage imageNamed:norImage] forState:UIControlStateNormal];
    }
    if (seletedImage !=nil && ![seletedImage isEqualToString:@""]) {
          [btn setImage:[UIImage imageNamed:seletedImage] forState:UIControlStateHighlighted];
    }
    [btn setTitle:title forState:UIControlStateNormal];
    // 设置FRAME
    [btn sizeToFit];
    // 点击事件
    [btn addTarget:target action:activity forControlEvents:UIControlEventTouchUpInside];
    // 设为barbuttonitem
    
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

+ (instancetype)initWith:(NSString *)norImage andSelecte:(NSString *)seletedImage andTitle:(NSString *)title andTarget:(id)target andActivity:(SEL)activity
{
    return [[UIBarButtonItem alloc] initWith:norImage andSelecte:seletedImage andTitle:title andTarget:target andActivity:activity];
}

@end
